//
//  ZJKVisitorViewController.swift
//  MicroBlog
//
//  Created by VAD on 16/4/16.
//  Copyright © 2016年 朱江坤. All rights reserved.
//

import UIKit

class ZJKVisitorViewController: UITableViewController,ZJKVisitorViewDelegate {

    //用户是否登录
    var userlogin: Bool = ZJKUserAccountViewModel.sharedViewModel.isLogin
    
    //在loadView里面判断用户是否登录,没有登录就初始化访客视频并添加到view上
    override func loadView() {
        
        userlogin ? super.loadView() : setupVisitorView()
        
    }
    private func setupVisitorView(){
        
        view = visitorView
        
        //设置左右2个item
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerButtonClick")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginButtonClick")
    }
    
// MARK: - 实现协议里面的方法
    //点击登录事件的点击方法
    func loginButtonClick() {
        print("点击的登录按钮")
        
        //初始化oauth登录控制器
        let vc = ZJKOAuthViewController()
        
        //把oauth登录控制器moda出来
        self.presentViewController(UINavigationController(rootViewController: vc), animated: true, completion: nil)
    }
    
    //点击注册事件的点击方法
    func registerButtonClick() {
        print("点击了注册按钮")
    }
    //懒加载控件
    lazy var visitorView: ZJKVisitorView = {
        
        let view = ZJKVisitorView()
        
        view.delegate = self
        
        return view
    }()

}
